import React, { Component } from 'react'
export default class Table extends Component {
    del=(id)=>{
        console.log(id,this.props);
    }
  render() {
    // console.log(this.props.list)
    let tbody;
    if( this.props.list.length>0){
        tbody=this.props.list.map(v=>{
            return (
                <tr key={v.id}>
                <td>{v.user}</td>
                <td>{v.age}</td>
                <td>
                    <button onClick={ ()=>this.del(v.id) }>删除</button>
                </td>
            </tr>
            )
        })
    }else{
        tbody = <tr>
            <th colSpan={3}>暂无数据</th>
        </tr>
    }
    return (
        <table border="1">
        <thead>
            <tr>
                <th>姓名</th>
                <th>年龄</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            {
              tbody  
            }
        </tbody>
    </table>
    )
  }
}
